package com.example.servicea.main;

/**
 * @author acer
 */
public class MaiPiao implements Runnable {

    private Integer num;

    public MaiPiao(Integer num) {
        this.num = num;
    }

    // 一个执行逻辑

    @Override
    public void run() {

        while (num >= 1) {
            try {
                // 付款....
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (MaiPiao.class) {
                if (num < 1) {
                    break;
                }
                System.out.println(Thread.currentThread().getName() + ": 卖出第" + num + "张票");
                num--;
            }
        }
    }


    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }
}
